package com.goods.controller;

import com.goods.resp.Item;
import com.goods.resp.RepsVo;
import com.goods.service.IGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/goods")
public class GoodsController {


    @Autowired
    private IGoodsService goodsService;

    /**
     * 根据商品id获取商品信息
     * @param goodsId
     * @return
     */
    @RequestMapping("/query/{goodsId}")
    public RepsVo<Item> queryByGoodsId(@PathVariable("goodsId") String goodsId,
                                        HttpServletRequest req){

//        String body = IOUtils.toString(null);

        //获取请求的token

        RepsVo<Item> repsVo = new RepsVo<Item>();

        Item item = goodsService.getItemById(goodsId);
        System.out.println("#############item###########" + item);


        repsVo.setData(item);
        repsVo.setCode("0");
        repsVo.setMsg("查询成功");
        return repsVo;

    }
}
